import { SettingsModel } from 'server/models/Settings'

export default defineEventHandler(async (event) => {
  try {
    const analytics = await SettingsModel.getAnalytics()
    
    if (!analytics || Object.keys(analytics).length === 0) {
      return {
        success: false,
        message: '统计代码信息不存在',
        data: null
      }
    }

    return {
      success: true,
      message: '获取统计代码信息成功',
      data: analytics
    }
  } catch (error: any) {
    console.error('获取统计代码信息失败:', error)
    
    return {
      success: false,
      message: `获取统计代码信息失败: ${error.message}`,
      data: null
    }
  }
})